package com.gugee.tiktok.common.model.dal.blogger;

import com.gugee.tiktok.common.model.mysql.BloggerFansPortrait;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface BloggerFansPortraitRepository extends CrudRepository<BloggerFansPortrait, Long> {
    /**
     * 根据awemeId 查询
     * @param awemeId
     * @return
     */
    Optional<BloggerFansPortrait> findByAwemeId(long awemeId);

    /**
     * 根据awemeId 更新时间及待更新数 查询
     * @param awemeId
     * @param recentTime
     * @param disabilityRate
     * @return
     */
    @Query("select * from blogger_fans_portrait t " +
            " where t.aweme_id = :awemeId and t.update_time > :recentTime " +
            " and t.need_analyze_blogger_count * 100 / t.comments_sample_count < :disabilityRate ")
    Optional<BloggerFansPortrait> findByAwemeIdAndUpdateTimeAndNeedAnalyzeBloggerCount(long awemeId,long recentTime,int disabilityRate);

    /**
     * 根据 uid及限制时间 查询粉丝画像数据
     * @param uid 博主id
     * @return
     */
    @Query("SELECT t.* FROM blogger_fans_portrait t WHERE t.uid = :uid  AND t.aweme_create_time >= :limitTime ")
    List<BloggerFansPortrait> findByUid(long uid, int limitTime);
}
